<?php

class UserModel extends Model{
	public $table='user';
	public $auto=array(
		array('restime','time','function',2,1)
	);
	public $validate=array(
				array('username','user:6,20','用户名长度为6~20个字符',2,3),
				array('password','minlen:6','密码长度为6~20个字符',2,3),
				array('password','maxlen:20','密码长度为6~20个字符',2,3),
				array('password2','confirm:password','两次密码不一致',2,3),
			);
	
	//新用户注册
	public function addUser(){
		if(!$this->create()) return false;
		$username=trim(Q('post.username'));
		if(M('user')->where("username='{$username}'")->find()){
			$this->error='用户名重复';
			return false; 
		}
		$this->data['password']=Q('post.password','','md5');
		return $this->add();
	}
	
	
}
    
    
    
?>